﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Security.Permissions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace InteSoft.Web.ExternalResourceLoader
{
    [AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class ContentInfo : ConfigurationElement
    {
        private static ConfigurationProperty _propContentRoot;
        private static ConfigurationPropertyCollection _properties;

        internal ContentInfo()
        {
            EnsureStaticPropertyBag();
        }

        private static ConfigurationPropertyCollection EnsureStaticPropertyBag()
        {
            if (_properties == null)
            {
                _propContentRoot = new ConfigurationProperty("contentRoot", typeof(string), null, null, new StringValidator(1), ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);

                _properties = new ConfigurationPropertyCollection
                                  {
                                      _propContentRoot
                                  };
            }
            return _properties;
        }

        public ContentInfo(string domain) : this()
        {
            ContentRoot = domain;
        }

        public override bool Equals(object namespaceInformation)
        {
            ContentInfo info = namespaceInformation as ContentInfo;
            return ((info != null) && (ContentRoot == info.ContentRoot));
        }

        public override int GetHashCode()
        {
            return ContentRoot.GetHashCode();
        }

        [StringValidator(MinLength = 1), ConfigurationProperty("contentRoot", IsRequired = true, IsKey = true)]
        public string ContentRoot
        {
            get { return (string)base[_propContentRoot]; }
            set { base[_propContentRoot] = value; }
        }

        protected override ConfigurationPropertyCollection Properties
        {
            get { return EnsureStaticPropertyBag(); }
        }
    }
}
